/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.vportal.portlet.edirectory.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.util.PortalUtil;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import com.vportal.portlet.edirectory.model.EDDepartment;
import com.vportal.portlet.edirectory.model.EDDepartmentModel;
import com.vportal.portlet.edirectory.model.EDDepartmentSoap;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * The base model implementation for the EDDepartment service. Represents a row in the &quot;EDDepartment&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.vportal.portlet.edirectory.model.EDDepartmentModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link EDDepartmentImpl}.
 * </p>
 *
 * @author HOAN
 * @see EDDepartmentImpl
 * @see com.vportal.portlet.edirectory.model.EDDepartment
 * @see com.vportal.portlet.edirectory.model.EDDepartmentModel
 * @generated
 */
@JSON(strict = true)
public class EDDepartmentModelImpl extends BaseModelImpl<EDDepartment>
	implements EDDepartmentModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a e d department model instance should use the {@link com.vportal.portlet.edirectory.model.EDDepartment} interface instead.
	 */
	public static final String TABLE_NAME = "EDDepartment";
	public static final Object[][] TABLE_COLUMNS = {
			{ "id_", Types.BIGINT },
			{ "createdDate", Types.TIMESTAMP },
			{ "name", Types.VARCHAR },
			{ "parent", Types.BIGINT },
			{ "phone", Types.VARCHAR },
			{ "fax", Types.VARCHAR },
			{ "levelEd", Types.BIGINT },
			{ "email", Types.VARCHAR },
			{ "address", Types.VARCHAR },
			{ "description", Types.VARCHAR },
			{ "website", Types.VARCHAR },
			{ "imgurl", Types.VARCHAR },
			{ "companyId", Types.BIGINT },
			{ "groupId", Types.BIGINT },
			{ "userId", Types.BIGINT },
			{ "languageId", Types.VARCHAR },
			{ "domainId", Types.VARCHAR }
		};
	public static final String TABLE_SQL_CREATE = "create table EDDepartment (id_ LONG not null primary key,createdDate DATE null,name VARCHAR(500) null,parent LONG,phone VARCHAR(75) null,fax VARCHAR(75) null,levelEd LONG,email VARCHAR(75) null,address VARCHAR(500) null,description VARCHAR(1000) null,website VARCHAR(100) null,imgurl VARCHAR(75) null,companyId LONG,groupId LONG,userId LONG,languageId VARCHAR(75) null,domainId VARCHAR(75) null)";
	public static final String TABLE_SQL_DROP = "drop table EDDepartment";
	public static final String ORDER_BY_JPQL = " ORDER BY edDepartment.levelEd ASC";
	public static final String ORDER_BY_SQL = " ORDER BY EDDepartment.levelEd ASC";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.com.vportal.portlet.edirectory.model.EDDepartment"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.vportal.portlet.edirectory.model.EDDepartment"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.com.vportal.portlet.edirectory.model.EDDepartment"),
			true);
	public static long DOMAINID_COLUMN_BITMASK = 1L;
	public static long GROUPID_COLUMN_BITMASK = 2L;
	public static long ID_COLUMN_BITMASK = 4L;
	public static long LANGUAGEID_COLUMN_BITMASK = 8L;
	public static long LEVELED_COLUMN_BITMASK = 16L;
	public static long PARENT_COLUMN_BITMASK = 32L;

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static EDDepartment toModel(EDDepartmentSoap soapModel) {
		EDDepartment model = new EDDepartmentImpl();

		model.setId(soapModel.getId());
		model.setCreatedDate(soapModel.getCreatedDate());
		model.setName(soapModel.getName());
		model.setParent(soapModel.getParent());
		model.setPhone(soapModel.getPhone());
		model.setFax(soapModel.getFax());
		model.setLevelEd(soapModel.getLevelEd());
		model.setEmail(soapModel.getEmail());
		model.setAddress(soapModel.getAddress());
		model.setDescription(soapModel.getDescription());
		model.setWebsite(soapModel.getWebsite());
		model.setImgurl(soapModel.getImgurl());
		model.setCompanyId(soapModel.getCompanyId());
		model.setGroupId(soapModel.getGroupId());
		model.setUserId(soapModel.getUserId());
		model.setLanguageId(soapModel.getLanguageId());
		model.setDomainId(soapModel.getDomainId());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<EDDepartment> toModels(EDDepartmentSoap[] soapModels) {
		List<EDDepartment> models = new ArrayList<EDDepartment>(soapModels.length);

		for (EDDepartmentSoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.com.vportal.portlet.edirectory.model.EDDepartment"));

	public EDDepartmentModelImpl() {
	}

	public long getPrimaryKey() {
		return _id;
	}

	public void setPrimaryKey(long primaryKey) {
		setId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_id);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	public Class<?> getModelClass() {
		return EDDepartment.class;
	}

	public String getModelClassName() {
		return EDDepartment.class.getName();
	}

	@JSON
	public long getId() {
		return _id;
	}

	public void setId(long id) {
		_columnBitmask |= ID_COLUMN_BITMASK;

		if (!_setOriginalId) {
			_setOriginalId = true;

			_originalId = _id;
		}

		_id = id;
	}

	public long getOriginalId() {
		return _originalId;
	}

	@JSON
	public Date getCreatedDate() {
		return _createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		_createdDate = createdDate;
	}

	@JSON
	public String getName() {
		if (_name == null) {
			return StringPool.BLANK;
		}
		else {
			return _name;
		}
	}

	public void setName(String name) {
		_name = name;
	}

	@JSON
	public long getParent() {
		return _parent;
	}

	public void setParent(long parent) {
		_columnBitmask |= PARENT_COLUMN_BITMASK;

		if (!_setOriginalParent) {
			_setOriginalParent = true;

			_originalParent = _parent;
		}

		_parent = parent;
	}

	public long getOriginalParent() {
		return _originalParent;
	}

	@JSON
	public String getPhone() {
		if (_phone == null) {
			return StringPool.BLANK;
		}
		else {
			return _phone;
		}
	}

	public void setPhone(String phone) {
		_phone = phone;
	}

	@JSON
	public String getFax() {
		if (_fax == null) {
			return StringPool.BLANK;
		}
		else {
			return _fax;
		}
	}

	public void setFax(String fax) {
		_fax = fax;
	}

	@JSON
	public long getLevelEd() {
		return _levelEd;
	}

	public void setLevelEd(long levelEd) {
		_columnBitmask = -1L;

		if (!_setOriginalLevelEd) {
			_setOriginalLevelEd = true;

			_originalLevelEd = _levelEd;
		}

		_levelEd = levelEd;
	}

	public long getOriginalLevelEd() {
		return _originalLevelEd;
	}

	@JSON
	public String getEmail() {
		if (_email == null) {
			return StringPool.BLANK;
		}
		else {
			return _email;
		}
	}

	public void setEmail(String email) {
		_email = email;
	}

	@JSON
	public String getAddress() {
		if (_address == null) {
			return StringPool.BLANK;
		}
		else {
			return _address;
		}
	}

	public void setAddress(String address) {
		_address = address;
	}

	@JSON
	public String getDescription() {
		if (_description == null) {
			return StringPool.BLANK;
		}
		else {
			return _description;
		}
	}

	public void setDescription(String description) {
		_description = description;
	}

	@JSON
	public String getWebsite() {
		if (_website == null) {
			return StringPool.BLANK;
		}
		else {
			return _website;
		}
	}

	public void setWebsite(String website) {
		_website = website;
	}

	@JSON
	public String getImgurl() {
		if (_imgurl == null) {
			return StringPool.BLANK;
		}
		else {
			return _imgurl;
		}
	}

	public void setImgurl(String imgurl) {
		_imgurl = imgurl;
	}

	@JSON
	public long getCompanyId() {
		return _companyId;
	}

	public void setCompanyId(long companyId) {
		_companyId = companyId;
	}

	@JSON
	public long getGroupId() {
		return _groupId;
	}

	public void setGroupId(long groupId) {
		_columnBitmask |= GROUPID_COLUMN_BITMASK;

		if (!_setOriginalGroupId) {
			_setOriginalGroupId = true;

			_originalGroupId = _groupId;
		}

		_groupId = groupId;
	}

	public long getOriginalGroupId() {
		return _originalGroupId;
	}

	@JSON
	public long getUserId() {
		return _userId;
	}

	public void setUserId(long userId) {
		_userId = userId;
	}

	public String getUserUuid() throws SystemException {
		return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
	}

	public void setUserUuid(String userUuid) {
		_userUuid = userUuid;
	}

	@JSON
	public String getLanguageId() {
		if (_languageId == null) {
			return StringPool.BLANK;
		}
		else {
			return _languageId;
		}
	}

	public void setLanguageId(String languageId) {
		_columnBitmask |= LANGUAGEID_COLUMN_BITMASK;

		if (_originalLanguageId == null) {
			_originalLanguageId = _languageId;
		}

		_languageId = languageId;
	}

	public String getOriginalLanguageId() {
		return GetterUtil.getString(_originalLanguageId);
	}

	@JSON
	public String getDomainId() {
		if (_domainId == null) {
			return StringPool.BLANK;
		}
		else {
			return _domainId;
		}
	}

	public void setDomainId(String domainId) {
		_columnBitmask |= DOMAINID_COLUMN_BITMASK;

		if (_originalDomainId == null) {
			_originalDomainId = _domainId;
		}

		_domainId = domainId;
	}

	public String getOriginalDomainId() {
		return GetterUtil.getString(_originalDomainId);
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

	@Override
	public EDDepartment toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (EDDepartment)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		if (_expandoBridge == null) {
			_expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(getCompanyId(),
					EDDepartment.class.getName(), getPrimaryKey());
		}

		return _expandoBridge;
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		getExpandoBridge().setAttributes(serviceContext);
	}

	@Override
	public Object clone() {
		EDDepartmentImpl edDepartmentImpl = new EDDepartmentImpl();

		edDepartmentImpl.setId(getId());
		edDepartmentImpl.setCreatedDate(getCreatedDate());
		edDepartmentImpl.setName(getName());
		edDepartmentImpl.setParent(getParent());
		edDepartmentImpl.setPhone(getPhone());
		edDepartmentImpl.setFax(getFax());
		edDepartmentImpl.setLevelEd(getLevelEd());
		edDepartmentImpl.setEmail(getEmail());
		edDepartmentImpl.setAddress(getAddress());
		edDepartmentImpl.setDescription(getDescription());
		edDepartmentImpl.setWebsite(getWebsite());
		edDepartmentImpl.setImgurl(getImgurl());
		edDepartmentImpl.setCompanyId(getCompanyId());
		edDepartmentImpl.setGroupId(getGroupId());
		edDepartmentImpl.setUserId(getUserId());
		edDepartmentImpl.setLanguageId(getLanguageId());
		edDepartmentImpl.setDomainId(getDomainId());

		edDepartmentImpl.resetOriginalValues();

		return edDepartmentImpl;
	}

	public int compareTo(EDDepartment edDepartment) {
		int value = 0;

		if (getLevelEd() < edDepartment.getLevelEd()) {
			value = -1;
		}
		else if (getLevelEd() > edDepartment.getLevelEd()) {
			value = 1;
		}
		else {
			value = 0;
		}

		if (value != 0) {
			return value;
		}

		return 0;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		EDDepartment edDepartment = null;

		try {
			edDepartment = (EDDepartment)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = edDepartment.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
		EDDepartmentModelImpl edDepartmentModelImpl = this;

		edDepartmentModelImpl._originalId = edDepartmentModelImpl._id;

		edDepartmentModelImpl._setOriginalId = false;

		edDepartmentModelImpl._originalParent = edDepartmentModelImpl._parent;

		edDepartmentModelImpl._setOriginalParent = false;

		edDepartmentModelImpl._originalLevelEd = edDepartmentModelImpl._levelEd;

		edDepartmentModelImpl._setOriginalLevelEd = false;

		edDepartmentModelImpl._originalGroupId = edDepartmentModelImpl._groupId;

		edDepartmentModelImpl._setOriginalGroupId = false;

		edDepartmentModelImpl._originalLanguageId = edDepartmentModelImpl._languageId;

		edDepartmentModelImpl._originalDomainId = edDepartmentModelImpl._domainId;

		edDepartmentModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<EDDepartment> toCacheModel() {
		EDDepartmentCacheModel edDepartmentCacheModel = new EDDepartmentCacheModel();

		edDepartmentCacheModel.id = getId();

		Date createdDate = getCreatedDate();

		if (createdDate != null) {
			edDepartmentCacheModel.createdDate = createdDate.getTime();
		}
		else {
			edDepartmentCacheModel.createdDate = Long.MIN_VALUE;
		}

		edDepartmentCacheModel.name = getName();

		String name = edDepartmentCacheModel.name;

		if ((name != null) && (name.length() == 0)) {
			edDepartmentCacheModel.name = null;
		}

		edDepartmentCacheModel.parent = getParent();

		edDepartmentCacheModel.phone = getPhone();

		String phone = edDepartmentCacheModel.phone;

		if ((phone != null) && (phone.length() == 0)) {
			edDepartmentCacheModel.phone = null;
		}

		edDepartmentCacheModel.fax = getFax();

		String fax = edDepartmentCacheModel.fax;

		if ((fax != null) && (fax.length() == 0)) {
			edDepartmentCacheModel.fax = null;
		}

		edDepartmentCacheModel.levelEd = getLevelEd();

		edDepartmentCacheModel.email = getEmail();

		String email = edDepartmentCacheModel.email;

		if ((email != null) && (email.length() == 0)) {
			edDepartmentCacheModel.email = null;
		}

		edDepartmentCacheModel.address = getAddress();

		String address = edDepartmentCacheModel.address;

		if ((address != null) && (address.length() == 0)) {
			edDepartmentCacheModel.address = null;
		}

		edDepartmentCacheModel.description = getDescription();

		String description = edDepartmentCacheModel.description;

		if ((description != null) && (description.length() == 0)) {
			edDepartmentCacheModel.description = null;
		}

		edDepartmentCacheModel.website = getWebsite();

		String website = edDepartmentCacheModel.website;

		if ((website != null) && (website.length() == 0)) {
			edDepartmentCacheModel.website = null;
		}

		edDepartmentCacheModel.imgurl = getImgurl();

		String imgurl = edDepartmentCacheModel.imgurl;

		if ((imgurl != null) && (imgurl.length() == 0)) {
			edDepartmentCacheModel.imgurl = null;
		}

		edDepartmentCacheModel.companyId = getCompanyId();

		edDepartmentCacheModel.groupId = getGroupId();

		edDepartmentCacheModel.userId = getUserId();

		edDepartmentCacheModel.languageId = getLanguageId();

		String languageId = edDepartmentCacheModel.languageId;

		if ((languageId != null) && (languageId.length() == 0)) {
			edDepartmentCacheModel.languageId = null;
		}

		edDepartmentCacheModel.domainId = getDomainId();

		String domainId = edDepartmentCacheModel.domainId;

		if ((domainId != null) && (domainId.length() == 0)) {
			edDepartmentCacheModel.domainId = null;
		}

		return edDepartmentCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(35);

		sb.append("{id=");
		sb.append(getId());
		sb.append(", createdDate=");
		sb.append(getCreatedDate());
		sb.append(", name=");
		sb.append(getName());
		sb.append(", parent=");
		sb.append(getParent());
		sb.append(", phone=");
		sb.append(getPhone());
		sb.append(", fax=");
		sb.append(getFax());
		sb.append(", levelEd=");
		sb.append(getLevelEd());
		sb.append(", email=");
		sb.append(getEmail());
		sb.append(", address=");
		sb.append(getAddress());
		sb.append(", description=");
		sb.append(getDescription());
		sb.append(", website=");
		sb.append(getWebsite());
		sb.append(", imgurl=");
		sb.append(getImgurl());
		sb.append(", companyId=");
		sb.append(getCompanyId());
		sb.append(", groupId=");
		sb.append(getGroupId());
		sb.append(", userId=");
		sb.append(getUserId());
		sb.append(", languageId=");
		sb.append(getLanguageId());
		sb.append(", domainId=");
		sb.append(getDomainId());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(55);

		sb.append("<model><model-name>");
		sb.append("com.vportal.portlet.edirectory.model.EDDepartment");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>id</column-name><column-value><![CDATA[");
		sb.append(getId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>createdDate</column-name><column-value><![CDATA[");
		sb.append(getCreatedDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>name</column-name><column-value><![CDATA[");
		sb.append(getName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>parent</column-name><column-value><![CDATA[");
		sb.append(getParent());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>phone</column-name><column-value><![CDATA[");
		sb.append(getPhone());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>fax</column-name><column-value><![CDATA[");
		sb.append(getFax());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>levelEd</column-name><column-value><![CDATA[");
		sb.append(getLevelEd());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>email</column-name><column-value><![CDATA[");
		sb.append(getEmail());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>address</column-name><column-value><![CDATA[");
		sb.append(getAddress());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>description</column-name><column-value><![CDATA[");
		sb.append(getDescription());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>website</column-name><column-value><![CDATA[");
		sb.append(getWebsite());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>imgurl</column-name><column-value><![CDATA[");
		sb.append(getImgurl());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>companyId</column-name><column-value><![CDATA[");
		sb.append(getCompanyId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>groupId</column-name><column-value><![CDATA[");
		sb.append(getGroupId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>userId</column-name><column-value><![CDATA[");
		sb.append(getUserId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>languageId</column-name><column-value><![CDATA[");
		sb.append(getLanguageId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>domainId</column-name><column-value><![CDATA[");
		sb.append(getDomainId());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = EDDepartment.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			EDDepartment.class
		};
	private long _id;
	private long _originalId;
	private boolean _setOriginalId;
	private Date _createdDate;
	private String _name;
	private long _parent;
	private long _originalParent;
	private boolean _setOriginalParent;
	private String _phone;
	private String _fax;
	private long _levelEd;
	private long _originalLevelEd;
	private boolean _setOriginalLevelEd;
	private String _email;
	private String _address;
	private String _description;
	private String _website;
	private String _imgurl;
	private long _companyId;
	private long _groupId;
	private long _originalGroupId;
	private boolean _setOriginalGroupId;
	private long _userId;
	private String _userUuid;
	private String _languageId;
	private String _originalLanguageId;
	private String _domainId;
	private String _originalDomainId;
	private transient ExpandoBridge _expandoBridge;
	private long _columnBitmask;
	private EDDepartment _escapedModelProxy;
}